#include <iostream>
#include "lvx_int.h"
#include "gprmc.h"
#include "lpms_int.h"
#include <thread>
#include <signal.h>
#include "time_info.h"

CTimeInfo * g_run_duration = NULL;

#define PPS_MERGE 1

#if PPS_MERGE

#include "pps.h"
#endif

using namespace std;

extern bool printThreadIsRunning;


void handler(int no)
{ 
    printf("received signal:%d\n",no);   
    if(no==15)   
    {       
        
        flag_exit_gps = 1;
        flag_exit_lpms = 1;
        printThreadIsRunning = false;
        flag_exit_lvx = 1;
#if PPS_MERGE      
        flag_exit_pps = 1;
#endif
    }
}


//#include <thread>
int main(int argc, char * argv[])
{

    signal(15,handler);
    g_run_duration = new CTimeInfo();

    g_run_duration->set_start_time();
    rising_time_refreshed = 0;
    
    thread lvx_thread(main_lvx);
    
    thread gps_thread(main_gps);

    lpms_argc = 3;
    const char * com_port_lpms = "/dev/gd_USB";
    const char * com_port_rate = "115200";
    
    memcpy(lpms_argv1,com_port_lpms,strlen(com_port_lpms)+1);
    memcpy(lpms_argv2,com_port_rate,strlen(com_port_rate)+1);
    thread lpms_thread(main_lpms);
#if PPS_MERGE
    thread pps_thread(main_pps);

    pps_thread.join();
#endif
    lpms_thread.join(); 
    lvx_thread.join();
    gps_thread.join();
}
